package com.controller;

import com.pojo.SysUser;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
    @Autowired
    UserService userService;

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @RequestMapping("/list")
    public String getList(Model model){
        model.addAttribute("userList",userService.list());
        return "list";
    }

    @RequestMapping("/tjadd")
    public String TJAdd(SysUser sysUser){
        boolean result = userService.save(sysUser);
        if (result){
        return "redirect:list";
        }else {
            return "add";
        }
    }

    @RequestMapping("/addtj")
    public String Add(){
        return "add";
    }

    @RequestMapping("/delete")
    public String Delete(Integer usrId){
        userService.removeById(usrId);
        return "redirect:list";
    }
}
